package ioutil

import (
	"golang.org/x/exp/mmap"
	"io"
	"log"
)

func ReadByMmap(path string) ([]byte, error) {
	at, err := mmap.Open(path)
	if err != nil {
		log.Fatalf("err:%v\n", err.Error())
		return nil, err
	}
	_buff := make([]byte, at.Len())

	defer func(at *mmap.ReaderAt) {
		err := at.Close()
		if err != nil {
			log.Fatalf("err:%v\n", err.Error())
		}
	}(at)

	_, err = at.ReadAt(_buff, 0)
	if err != nil && err != io.EOF {
		log.Fatalf("err:%v\n", err.Error())
		return nil, err
	}
	return _buff, nil
}
